<?xml version="1.0" encoding="utf-8"?>
<!--
        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 2 of the License, or
        (at your option) any later version.
        
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
        
        You should have received a copy of the GNU General Public License
        along with this program; if not, write to the Free Software
        Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
        MA 02110-1301, USA.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:output method="html" omit-xml-declaration="yes"/>
	<xsl:template match="/">
		<div>
			<button style="width:200px" onClick="javasctipt:document.location.href = '../../../../bin/kernel.py?func=getMSPCSV';">Download Spare parts...</button>
			<button style="width:200px" onClick="javascript:parent.showDialog('uploadcsv');">Upload Spare parts...</button>
			<button style="width:200px" onClick="javascript:GetXLStable($('#xlstable').html().replace(/;/gi, ''));">Download XLS...</button>
			<table width="100%" id="xlstable">
				<tr bgcolor="#CCCCCC">
					<td align="center"></td>
					<td align="center">code</td>
					<td align="center">description</td>
					<td align="center">description rus</td>
					<td align="center">unit</td>
					<td align="center">integer?</td>
					<!--<td align="center">price</td>
					<td align="center">currency</td>-->
					<td align="center">safety stock</td>
					<td align="center">planning type</td>
					<td align="center">planning condition</td>
					<td align="center">model</td>
				</tr>
				<xsl:for-each select="main/msp">
					<tr bgcolor="#EEEEEE">
						<xsl:if test="position() mod 2 = 0">
							<xsl:attribute name="bgcolor">#CCCCCC</xsl:attribute>
						</xsl:if>
						<td width="17" align="center">
							<img src="../../img/edit.png" title="edit">
								<xsl:attribute name="onclick">
									javascript:parent.edititem(<xsl:value-of select="id"/>, '<xsl:value-of select="description_rus"/>');
								</xsl:attribute>
							</img>
						</td>
						<td><xsl:value-of select="code"/></td>
						<td><xsl:value-of select="description"/></td>
						<td><xsl:value-of select="description_rus"/></td>
						<td align="center">
							<xsl:variable name="varUnit"><xsl:value-of select="unit"/></xsl:variable>
							<xsl:for-each select="//main/unit">
								<xsl:if test="$varUnit=id">
									<xsl:value-of select="descr"/>
								</xsl:if>
							</xsl:for-each>					
						</td>
						<td align="center">
							<xsl:if test="integer=1">
								yes
							</xsl:if>
							<xsl:if test="integer=0">
								no
							</xsl:if>
						</td>
						<!--<td align="right"><xsl:value-of select="price"/></td>
						<td align="center">
							<xsl:variable name="varCurrency"><xsl:value-of select="currency"/></xsl:variable>
							<xsl:for-each select="//main/currency">
								<xsl:if test="$varCurrency=id">
									<xsl:value-of select="currency"/>
								</xsl:if>
							</xsl:for-each>
						</td>-->
						<td align="center"><xsl:value-of select="safety_stock"/></td>
						<td align="center">
							<xsl:if test="planning_type=1">
								SYSTEM
							</xsl:if>
							<xsl:if test="planning_type=0">
								MANUAL
							</xsl:if>
						</td>
						<td align="center"><xsl:value-of select="planning_condition"/>%</td>
						<td>
							<xsl:variable name="varModel"><xsl:value-of select="model"/></xsl:variable>
							<xsl:for-each select="//main/model_swap">
								<xsl:if test="select_id=$varModel">
									<xsl:variable name="varModelId"><xsl:value-of select="model_id"/></xsl:variable>
									<xsl:for-each select="//main/model">
										<xsl:if test="id=$varModelId">
											<xsl:value-of select="name"/><br />
										</xsl:if>
									</xsl:for-each>
									
								</xsl:if>
							</xsl:for-each>
						</td>
					</tr>
				</xsl:for-each>
			</table>
		</div>
    </xsl:template>
</xsl:stylesheet>
